home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld: Complete Mac Interactive
/
Macworld Complete Mac Interactive CD)(1994).iso
/
The Best of BMUG
/
Utilities
/
Text and Speech
/
Alpha.5.76
/
Tcl
/
SystemCode
/
think.tcl
< prev
next >
Wrap
Text File
|
1994-03-08
|
7KB
|
324 lines
# The commands so far are:
# "thinkFileName <index>|<name>" - Indexes start at '1'.
set THINK "THINK Project Manager"
set ALPHA "Alpha 5.72i"
# The following flags affect the "Run" command.
set runWithDebugger 1
set runWithGo 1
# 'ask ', 'yes ', or 'no '
set runWithUpdate "'yes '"
set runWithSaveDirty "'yes '"
proc thinkNumFiles {} {
global THINK
set str [AEBuild -r $THINK "core" "cnte" "----" {obj{want:type('PDOC'), from:'null'(), form:'indx', seld:1}} "kocl" "type('SFIL')"]
if {[regexp {[0-9]+} $str mtch]} {
return $mtch
} else {
error "Bad numfiles"
}
}
# Get list of files in current project.
proc projectFileList args {
watchCursor
set num [thinkNumFiles]
set files {}
if {[llength $args]} {
for {set i 1} {$i<=$num} {incr i} {
lappend files [thinkFileName -p $i]
}
} else {
for {set i 1} {$i<=$num} {incr i} {
lappend files [thinkFileName $i]
}
}
return $files
}
# Think reference 2.0 support. From the shell:
# dosc -c 'DanR' -k 'DanR' -e "'REF '" -s "PutScrap"
# tells think reference to find and display the correct reference.
# dosc -c 'DanR' -k 'DanR' -e 'TMPL' -s "PutScrap"
# queries Think Reference for a function template and IM reference,
# and displays information about the function in the background.
# The following function interprets the selected text as a function
# name and displays in an alert the function template.
proc thinkReferenceTemplate args {
if {[getPos] == [selEnd]} return
catch {dosc -c 'DanR' -k 'DanR' -e 'TMPL' -s [getSelect]} res
alertnote $res
}
#================================================================================
set lastTrap {}
proc insertTrapTemplate {} {
global lastTrap
if {![string length [checkRunning ThinkReference DanR referencePath]]} return
set text [getSelect]
if {![string length $text]} {
if {[catch {prompt "Trap name:" $lastTrap} text]} return
} else {
deleteText [getPos] [selEnd]
}
set lastTrap $text
if {[catch {thinkReference -t $text} out]} {
alertnote "THINK Reference not running..."
} else {
insertText $out
}
}
proc displayTrapTemplate {} {
global lastTrap
if {![string length [checkRunning ThinkReference DanR referencePath]]} return
set text {}
catch {set text [getSelect]}
if {![string length $text]} {
if {[catch {prompt "Trap name:" $lastTrap} text]} return
}
set lastTrap $text
if {[catch {thinkReference -t $text} out]} {
alertnote "THINK Reference not running..."
} else {
alertnote $out
}
}
proc lookupTrap {} {
global lastTrap
if {![string length [checkRunning ThinkReference DanR referencePath]]} return
set text {}
catch {set text [getSelect]}
if {![string length $text]} {
if {[catch {prompt "Trap name:" $lastTrap} text]} return
}
set lastTrap $text
if {[catch {thinkReference -l aesend $text}]} {
alertnote "THINK Reference not running..."
}
}
proc gotoReference {} {
catch {switchTo [checkRunning ThinkReference DanR referencePath]}
}
#================================================================================
proc think {} {
set name [checkRunning ThinkC KAHL thinkName]
if {![string length $name]} return
switchTo $name
}
proc searchNextFile {} {
thinkFinf
}
# The 'Files' menu can instantiate itself from the THINK Project Manager if
# it is running.
menu -n $thinkMenu {
"/-think"
"openHeader"
"setIncludepath…"
{menu -n thinkRef {
"gotoReference"
"(-"
"displayTrapTemplate"
"insertTrapTemplate"
"lookupTrap"
}}
"(-"
{menu -n {Project Files} {
"getProjectFiles"}}
"createProjectFileset"
"(-"
"/Kcompile"
"checkSyntax"
"searchNextFile"
"(-"
"add"
"addAndCompile"
"(-"
"disassemble"
"preprocess"
"(precompile"
"(-"
"/UbringUpToDate"
"make"
"(-"
"/Rrun"
}
makeFilesetMenu
proc getProjectFiles args {
menu -n {Project Files} -m -p projFile [lsort [projectFileList -p]]
}
proc projFile {menu name} {
edit [thinkFileName $name]
}
#===========================================================================
# Add fileset.
#===========================================================================
proc createProjectFileset {} {
global fileSets
global currFileSet
set name "Project"
set fileSets($name) [projectFileList]
addMenuItem -m choose $name
set currFileSet $name
}
#================================================================================
proc checkIncludepath {} {
global includePath
set bad 0
if {![info exists includePath]} {return [setIncludepath]}
foreach p [subVars $includePath] {
if {![file exists $p]} {set bad 1}
}
if ($bad) setIncludepath
}
proc setIncludepath {} {
global includePath HOME
set includePath {}
while {![catch {set path [get_directory]}]} {
lappend includePath $path
}
set fid [open "$HOME:Tcl:SystemCode:definitions.tcl" "a"]
puts $fid "set includePath \"$includePath\""
close $fid
}
proc openHeader {} {
global includePath
checkIncludepath
set path [subVars $includePath]
set fname [getSelect]
if {[string last ".h" $fname]=="-1"} {
set fname ${fname}.h
}
set win [lindex [winNames -f] 0]
if {[string match *:* $win]} {
lappend path [file dirname $win]
}
foreach dir $path {
if {[file exists $dir:$fname]} {
edit $dir:$fname
return
}
}
beep
message "No such header file"
}
#================================================================================
proc sendOpenEvent {filler appname fname} {
AEBuild $appname aevt odoc "----" [concat {[alis(«} [coerce TEXT $fname -x alis] {»)]}]
}
proc compile {} {
sendCompileEvent CMPL
}
proc checkSyntax {} {
sendCompileEvent SNTX
}
proc disassemble {} {
sendCompileEvent DASM
}
proc preprocess {} {
"Think isn't quite there yet..."
return
}
proc sendCompileEvent {event} {
global THINK ALPHA
set name [lindex [winNames -f] 0]
switchTo $THINK
set res [AEBuild -r -t 6000 $THINK KAHL $event "----" [join [concat {obj\{want:type('SFIL'), from:'null'(), form:'name', seld:“} [file tail $name] {”\}}] ""]]
switchTo $ALPHA
return $res
}
proc add {} {
global THINK
set fname [lindex [winNames -f] 0]
AEBuild $THINK core crel "data" [concat {[alis(«} [coerce TEXT $fname -x alis] {»)]}] "kocl" "type('SFIL')"
}
proc addAndCompile {} {
add
compile
}
proc precompile {} {
alertnote "Someday…"
}
proc bringUpToDate {} {
alertnote "Someday…"
}
proc make {} {
global THINK ALPHA
switchTo $THINK
set res [AEBuild -r -t 6000 $THINK KAHL MAKE "CFLG" "long(«02»)" "----" {obj{want:type('PDOC'), from:'null'(), form:'indx', seld:1}}]
switchTo $ALPHA
return $res
}
proc run {} {
global runWithDebugger runWithGo runWithUpdate runWithSaveDirty THINK
set dbug [expr {$runWithDebugger ? "bool(«01»)" : "bool(«00»)"}]
set go [expr {$runWithGo ? "bool(«01»)" : "bool(«00»)"}]
switchTo $THINK
AEBuild -t 6000 -r $THINK KAHL "RUN " "DBUG" $dbug "GO " $go "UPDT" $runWithUpdate "savo" $runWithSaveDirty
}
proc cnt {} {
global THINK
AEBuild -t 6000 -r $THINK core cnte "----" {obj{want:type('PDOC'), from:'null'(), form:'indx', seld:1}} "kocl" "type('sfil')"
}
proc thinkFileName {arg} {
global THINK
set event [join [concat {obj\ \{want:type('prop'),\ from:obj\ \{want:type('SFIL'),\ from:'null'(),\ form:'indx',\ seld:} $arg {\},\ form:'prop',\ seld:type('FSS\ ')\}}] ""]
set blah [AEBuild -r $THINK "core" "getd" "----" $event]
regexp {«[0-9A-F]+»} $blah mtch
return [string trim $mtch "«»"]
}